const {
  override,
  addDecoratorsLegacy,
  disableEsLint,
  addBundleVisualizer,
  addWebpackAlias,
  adjustWorkbox,
  fixBabelImports,
  addLessLoader
} = require("customize-cra");
const path = require("path");

module.exports = override(
  // enable legacy decorators babel plugin
  addDecoratorsLegacy(),

  // disable eslint in webpack
  disableEsLint(),

  // add webpack bundle visualizer if BUNDLE_VISUALIZE flag is enabled
  process.env.BUNDLE_VISUALIZE === 1 && addBundleVisualizer(),

  // add an alias for "ag-grid-react" imports
  addWebpackAlias({
    '@': path.resolve('./src')
  }),

  // adjust the underlying workbox
  adjustWorkbox(wb =>
    Object.assign(wb, {
      skipWaiting: true,
      exclude: (wb.exclude || []).concat("index.html")
    })
  ),
  // 按需加载组件样式
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  }),
  //使用less-loader对源码重的less的变量进行设置antd自定义主题
  addLessLoader({
    javascriptEnabled: true,
    modifyVars: {
        "@brand-primary": '#64BFBB'
    }
  })
);